package com.example.servlet.ClassServlet;

import com.example.bean.Class;
import com.example.bean.Student;
import com.example.dao.ClassDao.ClassUpdateDao;
import com.example.dao.ClassDao.ClassUpdateDaoImp;
import com.example.dao.StudentDao.StudentUpdateDao;
import com.example.dao.StudentDao.StudentUpdateDaoImp;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(name = "UpdateServlet", value = "/classupdate")
public class ClassUpdateServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1.获取浏览器发来的信息
        response.setContentType("html/text;charset=utf-8");
        response.sendRedirect("classupdateTarget.jsp");

        String cname = request.getParameter("cname");
        System.out.println("该班级的名称为:"+cname);
        String cgrade = request.getParameter("cgrade");
        System.out.println("修改后的年级为:"+cgrade);
        String ctname = request.getParameter("ctname");
        System.out.println("修改后的班主任名称为:"+ctname);
        String cflag = request.getParameter("cflag");
        System.out.println("修改后的班级口号:"+cflag);
        String cnum = request.getParameter("cnum");
        System.out.println("修改后的班级人数为:"+cnum);

        //2.将数据交给Dao层进行处理
        Class cl=new Class(cname,cgrade,ctname,cflag,cnum);
        ClassUpdateDao classUpdateDao=new ClassUpdateDaoImp();
        int res = classUpdateDao.getClassUpdate(cl);

        //3.修改成功
        System.out.println("班级信息修改成功!");
    }
}
